package neu.soft.feignclient;

import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import neu.soft.entity.EntryOrder;
import neu.soft.entity.Inventory;
import neu.soft.exception.AppException;
import neu.soft.exception.AppExceptionCodeMsg;
import neu.soft.vo.ResultBean;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Component
@Slf4j
public class WarehouseFeignClientFallBackFactory implements FallbackFactory<WarehouseFeignClient> {
    @Override
    public WarehouseFeignClient create(Throwable throwable) {
        return new WarehouseFeignClient() {
            @Override
            public ResultBean<List<Map<String, Object>>> queryEntryOrder(Map<String, Object> map) {
                log.info(throwable.getMessage());
                return ResultBean.error(500, throwable.getMessage());
            }

            @Override
            public ResultBean<List<Map<String, Object>>> queryOutOrder(Map<String, Object> map) {
                log.info(throwable.getMessage());
                return ResultBean.error(500, throwable.getMessage());
            }

            @Override
            public ResultBean<Integer> queryInventoryNum(Map<String, Object> map) {
                log.info(throwable.getMessage());
                return ResultBean.error(500, throwable.getMessage());
            }

            @Override
            public List<Inventory> queryInventoryByCodeList(List<String> codeList) {
                log.info(throwable.getMessage());
                List<Inventory> inventoryList = new ArrayList<>();
                inventoryList.add(new Inventory("-1", "查询失败", 0, 1));
                return inventoryList;
            }
        };
    }
}
